package com.ycw.cs.service.hospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ycw.cs.api.entity.hospital.HospitalSet;
import com.ycw.cs.api.service.hospital.HospitalSetService;
import com.ycw.cs.common.response.ResponseResults;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "医院设置")
@RestController
@RequestMapping("/hospitalset")
public class HospitalSetController {


    @Autowired
    private HospitalSetService hospitalSetService;


    /**
     * 查询所有医院的信息(MyBatis-Plus的方式)
     * @return
     */
    @ApiOperation(value ="查询所有医院的信息(MyBatis-plus的方式)")
    @GetMapping("/findAllByPlus")
    public ResponseResults queryAllHostpitalByPlus(){
        ResponseResults results = ResponseResults.fail();
        List<HospitalSet> allHospital = hospitalSetService.findAllByPlus();
        if(allHospital !=null && !allHospital.isEmpty()){
            results = ResponseResults.ok();
            results.setList(allHospital);
        }
        return results;
    }

    /**
     * 查询所有医院的信息(MyBatis的方式)
     * @return
     */
    @ApiOperation(value ="查询所有医院的信息(MyBatis的方式)")
    @GetMapping("/findAll")
    public ResponseResults queryAllHostpital(){
        ResponseResults results = ResponseResults.fail();
        List<HospitalSet> allHospital = hospitalSetService.findAll();
        if(allHospital !=null && !allHospital.isEmpty()){
            results = ResponseResults.ok();
            results.setList(allHospital);
        }
        return results;
    }

    @ApiOperation(value ="根据ID删除相应的医院信息")
    @RequestMapping("/delete/{id}")
    public ResponseResults deleteHospitalById(@PathVariable Long id){
        ResponseResults results = ResponseResults.fail();
        boolean result = hospitalSetService.removeById(id);
        if(result){
            results = ResponseResults.ok();
        }
        return results;
    }

    /**
     * 分页查询医院的信息
     * @param current
     * @param limit
     * @param hosname
     * @param hoscode
     * @return
     */
    @ApiOperation(value ="分页查询医院的信息",notes = "传入参数:当前页、每页查询的数量、查询条件")
    @GetMapping("/findPageHospSet/{current}/{limit}")
    public ResponseResults queryHostpitalByCondition(@PathVariable long current,
                                                     @PathVariable long limit,
                                                     @RequestParam(value = "hosname",required = false) String hosname,
                                                     @RequestParam(value = "hoscode",required = false) String hoscode){
        ResponseResults results = ResponseResults.fail();
        HospitalSet hospitalSet=new HospitalSet();
        hospitalSet.setHosname(hosname);
        hospitalSet.setHoscode(hoscode);
        //创建page对象,传递当前页,每页记录数
        Page<HospitalSet> page=new Page<>(current,limit);
        Page<HospitalSet> hospitalPage = hospitalSetService.selectPage(page,hospitalSet);
        if(hospitalPage!=null){
            List<HospitalSet> pageRecords = hospitalPage.getRecords();
            if(pageRecords != null && !pageRecords.isEmpty()){
                results = ResponseResults.ok();
                results.setList(pageRecords);
            }
        }
        return results;
    }

    /**
     * 添加医院设置相关信息
     * @param hospitalSet
     * @return
     */
    public ResponseResults addHostpital(HospitalSet hospitalSet){
        return null;
    }

    /**
     * 修改医院信息
     * @param id
     * @return
     */
    public ResponseResults updteHostpital(@PathVariable Long id){
        return null;
    }

    /**
     * 批量删除医院信息
     * @param id
     * @return
     */
    public ResponseResults deleteHostpital(@PathVariable Long id){
        return null;
    }



}
